package cn.com.xuan.web.user;

import cn.com.xuan.dao.bean.UserVO;
import cn.com.xuan.service.UserVOService;
import org.apache.el.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/u")
public class UserController {

    @Autowired
    UserVOService userVOService;

    @ResponseBody
    @RequestMapping("/t")
    public Object test(){
        return "cn.com.xuan.web.UserController.test";
    }

    @ResponseBody
    @RequestMapping("/b")
    public Object addBatch(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        List<UserVO> users = new ArrayList<UserVO>();
        for (int i=0;i<5;i++) {
            String time = sdf.format(new Date());
            UserVO userVO = new UserVO();
            userVO.setUsername("username&"+time);
            userVO.setPassword("pwd&"+time);
            userVO.setRole("role&"+time);
            users.add(userVO);
        }
        return userVOService.insertOVBatch(users);
    }
}
